<template>
  <el-dialog v-model="dialogVisible" title="条码查询" width="900px">
    <el-form class="aceauForm" label-width="120px" :model="state.form">
      <el-row :gutter="12">
        <el-col :span="12">
          <el-form-item label="条码">
            <el-input v-model="state.form.barcode" placeholder="" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="存货编码">
            <el-input v-model="state.form.invcode" placeholder="" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="存货名称">
            <el-input v-model="state.form.invname" placeholder="" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="规格型号">
            <el-input v-model="state.form.invspec" placeholder="" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="批次号">
            <el-input v-model="state.form.invbatch" placeholder="" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="仓库">
            <el-select
              v-model="state.form.pkWh"
              class="m-2"
              clearable
              placeholder="选择仓库"
              style="width: 300px"
            >
              <el-option
                v-for="item in state.whList"
                :key="item.pkWh"
                :label="item.whName"
                :value="item.pkWh"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
          <el-form-item label="条码类型">
            <el-select
              v-model="state.form.type"
              class="m-2"
              clearable
              placeholder="选择条码类型"
              style="width: 300px"
            >
              <el-option
                v-for="item in state.typeList"
                :key="item.typeCode"
                :label="item.typeName"
                :value="item.typeCode"
              />
            </el-select>
          </el-form-item>
        </el-col> -->
        <el-col :span="12">
          <el-form-item label="创建日期">
            <el-date-picker
              v-model="state.form.queryDate"
              :clearable="false"
              range-separator="-"
              style="width: 100%"
              type="daterange"
              value-format="YYYY-MM-DD"
            />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogVisible = false">取消</el-button>
        <el-button type="primary" @click="query">查询</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
  import { localStorageConfig } from '@/config/localstorage.config'
  import { getWarehouseListApi } from '@/api/base/wh/index'
  const pkCorp = localStorage.getItem(localStorageConfig.__pkCorp)
  import dayjs from 'dayjs'
  const dialogVisible = ref(false)

  const state = reactive({
    form: {
      pkCorp: pkCorp,
      queryDate: [
        dayjs().subtract(7, 'day').format('YYYY-MM-DD'),
        dayjs().format('YYYY-MM-DD'),
      ],
    },
    whList: [],
    typeList: [],
  })
  const openDialog = () => {
    dialogVisible.value = true
    getWhList()
  }

  const getWhList = async () => {
    const { code, data } = await getWarehouseListApi({ pkCorp: pkCorp })
    if (code === 2000) {
      state.whList = data
    }
  }

  const query = () => {
    dialogVisible.value = false
    _emit('success-callback', state.form)
  }

  defineExpose({ openDialog })
  const _emit = defineEmits(['success-callback'])
</script>
